package com.learning.security.controller;

import com.learning.security.controller.vo.ApiSaveReqVO;
import com.learning.security.dal.dataobject.AdminApiDO;
import com.learning.security.service.AdminApiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin/api")
public class AdminApiController {
    @Autowired
    private AdminApiService adminApiService;

    @PostMapping("/create")
    public boolean createApi(@RequestBody ApiSaveReqVO reqVO) {
        return adminApiService.createApi(reqVO);
    }

    @PreAuthorize("hasRole('ADMIN') and @ss.hasPermission('system:api:edit')")
    @PostMapping("/get")
    public AdminApiDO getApiByPath(String requestURI) {
        return adminApiService.getApiByPath(requestURI);
    }
}
